package logic

import (
	"context"
	"gorm.io/gorm"
	"vipshop/models"

	"vipshop/vipshoprpc/internal/svc"
	"vipshop/vipshoprpc/vipshoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 完善信息
func (l *PerfectLogic) Perfect(in *vipshoprpc.PerfectRequest) (*vipshoprpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line

	user := models.User{
		Model:     gorm.Model{ID: uint(in.UserId)},
		Age:       int(in.Age),
		Address:   in.Address,
		HeadImage: in.HeadImage,
	}
	models.DB.Debug().Updates(&user)

	return &vipshoprpc.PerfectResponse{
		UserId: int64(user.ID),
	}, nil
}
